Don't Worry, Be Happy

256-color config for vim in putty

putty is an SSH and telnet client for windows users to connect to Linux systems.

When connected to Ubuntu Virtual machine, I use putty as a Linux terminal and I use vim as my editor to do some coding. Vim can be configured into a beautiful IDE but putty cannot show the beauty because putty is not a GUI mode.

putty vim 256 color problem

When I try to config vim with some interface, such as solarized, vim-airline or some general config to hilight the cursor line and cursor column in .vimrc:

1
2
3
4
set cursorline
set cursorcolumn
hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white

The effect is terrible and the variable can only support 8 colors. Some people may run into the problem such as someone in stackoverflow.
Yes right there must be some ways to solve the problem!!

putty

In the putty config, Window->colours, enable the xterm 256-colour mode
not found :P.

Also I set some colors here:
Default Forground: RGB(143,119,181)
Default Bold Forground: RGB(255,255,255)
Default Background: RBG(0,0,0)
Default Bold Background RGB(85,85,85)
Cursor Colour: RGB(240,94,28)
There is a japan traditional color website shows a varity of colors.

In Window->Appearance, set:
Font: Consolas
size: 14-point

Moreover, the configuration of putty must be save under a session. And the configuation is only effective the the single session. So I recommend you the tool putty manager, which can manage putty and winscp.

bash

In the ubuntu virtual machine, we need to change the ~/.bashrc, the terminal support 256-mode, so adding the script:

1
export TERM=xterm-256color

Rember to reopen a putty, or the .bashrc won’t be reload.

vim

add the script to .vimrc

1
2
3
if $TERM == "xterm-256color"
set t_Co=256
endif

Then it’s free to use the colorful plugins.

setting for solarized:

1
2
3
4
5
6
7
8
9
10
11
let g:solarized_bold = 0
let g:solarized_contrast = "low"
let g:solarized_termcolors = 256
if has('gui_running')
set background=light
else
set background=dark
endif
colorscheme solarized

setting for cursor:

1
2
3
4
set cursorline
set cursorcolumn
hi CursorLine cterm=NONE ctermbg=237 ctermfg=NONE guibg=darkred guifg=white
hi CursorColumn cterm=NONE ctermbg=235 ctermfg=NONE guibg=darkred guifg=white

Only cterm matters because we are not in gui mode. And the color can be quired in Xterm256 color table.

Final effect of putty with vim

not found :P not found :P not found :P

putty airline seperator font problem

Some people may find that in the effect, the seperator looks strange. The seperator should be ‘▶’. ‘>’ or ‘>>’ may look not that good. Also some people want to solve the symbol font problem.

As recommanded in the answer, we need to install the corresponding font in terminal, here means putty. While putty support the font installed in the windows system.
Here is the steps(prequest: have already solved the previous problem, xterm 256 color supported and vim-airline installed.):

  • download the powerline fonts, install them in windows, so that putty can support these fonts. You can also installed them in Ubuntu virtual machine in case of gui mode.
  • reopen putty
    1. Window-Apperance-Font set to a font downloaded, such as Hack.
    2. Window-Translation-Character Set set to UTF-8.
  • Verify your .vimrc and ubuntu VM support UTF-8.
  • Change the .vimrc file. The setting of seperator can be viewed with command in vim:

    1
    :help airline

    add the following to .vimrc:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    """"""""""""""""""""""
    " Conf for airline "
    """"""""""""""""""""""
    let g:airline_powerline_fonts = 1
    if !exists('g:airline_symbols')
    let g:airline_symbols = {}
    endif
    " powerline symbols
    let g:airline_left_sep = ''
    let g:airline_left_alt_sep = ''
    let g:airline_right_sep = ''
    let g:airline_right_alt_sep = ''
    let g:airline_symbols.branch = ''
    let g:airline_symbols.readonly = ''
    let g:airline_symbols.linenr = ''
    let g:airline#extensions#tabline#enabled = 1
    let g:airline#extensions#tabline#left_sep = ''
    let g:airline#extensions#tabline#left_alt_sep = ''
    let g:airline#extensions#tabline#tab_nr_type = 1 " tab number

The  is some the root of the problem. They look like this in the setting:
not found :P

final effect of powerline

Wow! That’s it! Much much much beautiful! Go coding!
not found :P

The setting of vim can be downloaded from my github, dotfile repository. Or run the command

1
$ git clone https://github.com/sukiand/dotfiles.git